# -*- coding:utf-8 -*-
# @FileName  :system_page.py
# @Time      :2020/10/28 11:11
# @Author    :Zhoujirong
# @Desc      :
from lib.pyse import Pyse
from faker import Faker
import time
fake=Faker(locale='zh_CN')
class BasicPage(object):
    def __init__(self):
        self.pyse = Pyse('chrome')
    def open(self):
        self.pyse.open('http://172.28.30.2:19090/creditplatformweb/login')
    def quit(self):
        self.pyse.quit()
class LoginPage(BasicPage):
    #反洗钱系统的登录
    # def sendUsername(self):
    #     #https://blog.csdn.net/hou_angela/article/details/80305828 参考
    #     tmp = 'xpath=>//input[@class="el-input__inner" and @tabindex="1"]'
    #     self.pyse.type(tmp,'99zjr')
    # def sendPasswd(self):
    #     pw = 'xpath=>//input[@class="el-input__inner" and @tabindex="2"]'
    #     self.pyse.type(pw,'111111-a')
    # def clickLogin(self):
    #     btLogin = 'xpath=>//div[@class="login-btn"]/button[@class="el-button el-button--primary el-button--small"]'
    #     self.pyse.click(btLogin)
    # def checkLogin(self):
    #     css =

   #查询系统的登录
   def sendUsername(self):
       css = 'css=>#username'
       self.pyse.type(css,'zjr')
   def sendPasswd(self):
        css = 'css=>#password'
        self.pyse.type(css,'111111-aA')
   def clickLogin(self):
        css = 'css=>#submit'
        self.pyse.click(css)
   def checkLogin(self,name):
       css = 'css=>a[href="creditLogout"]'
       return self.pyse.wait_and_save_exception(css,name)
   def system(self):
       css = 'xpath=>//a[@id="10000000"]'
       self.pyse.click(css)
# class OrgPage(LoginPage):
#     def org(self):
#         css = 'css=>a[lay-tips="机构管理"]'
#         self.pyse.click(css)
#     def iframe_org(self):
#         css = 'xpath=>//iframe[@src="systemOrg/list" and @class="layadmin-iframe" and @frameborder="0"]'
#         self.pyse.switch_to_frame(css)
#     def add_org(self):
#         time.sleep(3)
#         css = 'xpath=>//div[@class="btnWrap"]/ul/li/a[@class="createBtn xz_btn"]'
#         self.pyse.click(css)
# class AddOrg(OrgPage):
#     def iframe_OrgCreate(self):
#         css = 'css=>iframe[src="/creditplatformweb/systemOrg/createPage"]'
#         self.pyse.switch_to_frame(css)
#     def OrgName(self):#机构名称
#         time.sleep(5)
#         css = 'css=>input[name="orgName"]'
#         self.pyse.type(css,'测试部门')
#     def orgId(self):#机构代码
#         css = 'css=>input[name="orgId"]'
#         orgid = fake.pystr(min_chars=5, max_chars=16)#自定义长度的随机字符串
#         self.pyse.type(css,orgid)
#     # def openOrg(self):
#     #     css = 'css=>input[ value = "启用"]'
#     #     self.pyse.type(css,'启用')
#     # def typeOrg(self):
#     #     css = 'css=>input[value="非法人机构"]'
#     #     self.pyse.type(css,'非法人机构')
#     def upOrg(self):#上级机构
#         # js = "document.getElementsByClassName('orgTree validate[required] layui-input')[0].removeAttribute('readOnly');"
#         # self.pyse.js(js) #将只读的属性去掉，直接写“总行”进去，无法通过校验
#         # css = 'xpath=>//input[@class="orgTree validate[required] layui-input"]'  # 点击机构处
#         # self.pyse.click(css)
#
#
# ##定位不到元素
#         css = 'xpath=>//input[@class="orgTree validate[required] layui-input"]'#点击机构处
#         self.pyse.type(css,'总行')
#         css = 'xpath=>//input[@placeholder="请输入机构名称"]'#选定机构
#         self.pyse.type(css,'总行')
#         css = 'css=>a[class="layui-layer-btn0"]'#确认按钮
#         self.pyse.click(css)
#
#     def postCode(self):#邮编
#         css = 'css=>input[name="postCode"]'
#         postCode = fake.postcode()
#         self.pyse.type(css,postCode)
#     def linkMan(self):#联系人
#         css = 'css=>input[name="linkMan"]'
#         self.pyse.type(css,'周继蓉')
#     def linkMode(self):#联系方式
#         css = 'css=>input[name="linkMode"]'
#         phone = fake.phone_number()
#         self.pyse.type(css,phone)
#     def otherLinkMode(self):
#         css = 'css=>input[name="otherLinkMode"]'
#         otherPhone = fake.phone_number()
#         self.pyse.type(css,otherPhone)
#     def address(self):
#         css = 'css=>input[name="address"]'
#         address = fake.street_address()
#         self.pyse.type(css,address)
#     def area1(self):
#         css = 'css=>input[class="layui-input layui-unselect validate[required] citySelect"]'
#         self.pyse.click(css)
#         css = 'css=>dd[lay-value="110000"]'
#         self.pyse.click(css)
#     def remark(self):
#         css = 'css=>textarea[name="remark"]'
#         self.pyse.type(css, '机构添加zU')
#     def submitPage(self):
#         css = 'css=>#submitPage'
#         self.pyse.click(css)
#     def OrgOk(self):
#         css = 'css=>a[class="layui-layer-btn0"]'
#         self.pyse.click(css)
#     # def checkOrg(self, name):
#     #     css = 'css=>a[href="creditLogout"]'
#     #     return self.pyse.wait_and_save_exception(css, name)

# class Role(LoginPage):
#     def role(self):
#         css = 'css=>a[lay-tips="角色管理"]'
#         self.pyse.click(css)
#     def iframe_role(self):
#         css = 'css=>iframe[src="roleManage/roleList"]'
#         self.pyse.switch_to_frame(css)
#     def add_role(self):
#         css = 'css=>a[class="createBtn"]'
#         self.pyse.click(css)
#     def iframe_roleCreate(self):
#         css = 'css=>iframe[src="/creditplatformweb/roleManage/createPage"]'
#         self.pyse.switch_to_frame(css)
#     def roleName(self):
#         css = 'xpath=>//div[@class="layui-input-block"][3]'
#         self.pyse.type(css,'roletest')
#     def roleType(self):
#         css = 'css=>div[class="layui-select-title"]'
#         self.pyse.click(css)
#         css = 'xpath=>//div[@class="layui-unselect layui-form-select layui-form-selected"]/d1/dd[1]'
#         self.pyse.click()
#     def roleDescription(self):
#         css = 'css=>#form-validation-field-1'
#         self.pyse.type(css,'角色描述')
#     def roleSubmit(self):
#         css = 'css=>#submitPage'
#         self.pyse.click(css)

class User():
    pass

class updatePassword():
    pass

class Page():
    pass

if __name__ == "__main__":
    page = Page()
    page.open()
    page.sendUsername()
    page.sendPasswd()
    page.clickLogin()
    page.checkLogin(LoginPage)
    page.system()
    page.org()
    page.iframe_org()
    page.add_org()
    page.iframe_OrgCreate()
    page.OrgName()
    page.orgId()
    page.upOrg()
    page.postCode()
    page.linkMan()
    page.linkMode()
    page.otherLinkMode()
    page.address()
    page.area1()
    page.remark()
    page.submitPage()
    page.OrgOk()